﻿
////////////////////////////////////////////////////////////////////////////////////////////
// 文件名: ETL_SourceSystemBLL.gen.cs
//
// 模块名称: ETLSourceBll
//
// 作者: LPC
//
// 历史记录（记录修改记录，修改文件后请添加修改记录，注明修改时间、修改人，修改内容）:
// 13-1-31    LPC    创建文件
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Common;
using DAL;
using Model;
using System.IO;
using System.Text;

namespace BLL
{
    /// <summary>
    /// ETL_SourceSystem表业务逻辑层
    /// </summary>
    public partial class EtlSourceSystemBLL : BaseBLL
    {
        public EtlSourceSystemBLL(LoginInfo info)
        {
            loginInfo = info;
        }
        const string ErrorCodeSelect = "";    //查询异常编码
        const string ErrorCodeInsert = "";    //添加异常编码
        const string ErrorCodeUpdate = "";    //修改异常编码
        const string ErrorCodeDelete = "";    //删除异常编码

        //public ETL_SourceSystemBLL(IUserInfo user) : base(user)
        //{
        //}
        /// <summary>
        /// 创建BLL对象
        /// </summary>
        /// <summary>
        /// 根据GUID字段获取ETL_SourceSystemInfo实体对象
        /// </summary>
        /// <param name="guid">GUID</param>
        /// <returns>ETL_SourceSystemInfo实体对象</returns>
        public EtlSourceSystemInfo GetInfoById(string guid)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.GetInfoById(guid);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLSourceBll信息出错。",
                                String.Format("guid = {0}", guid));
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        /// <summary>
        /// 往ETL_SourceSystem表内添加新记录
        /// </summary>
        /// <param name="par"> </param>
        /// <returns>添加记录索引值</returns>
        public int Insert(IDataParameter[] par)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                int identity = dal.Insert(par);
                return identity;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "Insert", AppError.EROR, 0, ex, "添加ETLSourceBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        /// <summary>
        /// 更新ETL_SourceSystem表记录
        /// </summary>
        public int Update(EtlSourceSystemInfo mode)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.Update(mode);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "Update", AppError.EROR, 0, ex, "更新ETLSourceBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeUpdate, ex);
            }
        }

        /// <summary>
        /// 根据GUID字段获取ETL_SourceSystemInfo实体对象
        /// </summary>
        /// <param name="par"> </param>
        public void Delete(IDataParameter[] par)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                dal.Delete(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "Delete", AppError.EROR, 0, ex, "删除ETLSourceBll信息出错。",
                              "");
                throw new SystemException(ErrorCodeDelete, ex);
            }
        }

        /// <summary>
        /// 删除源系统配置信息
        /// </summary>
        /// <param name="par"> </param>
        public bool DelSysConfig(string sysID)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.DelSysConfig(sysID);
            }
            catch (Exception ex)
            { 
                throw ex;
            }
        }

        /// <summary>
        /// 添加源系统回调配置信息
        /// </summary>
        /// <param name="par"> </param>
        public bool AddCallBack(ETLCallBackConfig model)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.AddCallBack(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 添加源系统回调配置参数信息
        /// </summary>
        /// <param name="par"> </param>
        public bool AddCallBackParas(ETLCallBackPara model)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.AddCallBackParas(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据GUID字段获取ETL_SourceSystemInfo实体对象
        /// </summary>
        /// <returns>List<ETL_SourceSystemInfo/>实体对象</returns>
        public IList<EtlSourceSystemInfo> GetList(IDataParameter[] par)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.GetList(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLSourceBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }
        public int GetETLStatusBySysID(string sysID)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.GetETLStatusBySysID(sysID);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLSourceBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        /// <summary>
        /// 根据GUID字段获取ETL_SourceSystemInfo实体对象
        /// </summary>
        /// <returns>List<ETL_SourceSystemInfo/>实体对象</returns>
        public int GetListCount(IDataParameter[] par)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.GetListCount(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLSourceBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        public DataTable GetPathList(string sql, SqlParameter[] para)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.GetPathList(sql, para);
            }
            catch (Exception ex)
            { 
                throw   ex;
            }
        }

        public IList<ETLDbConfig> GetETLDbConfigList(IDataParameter[] dataparams)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetETLDbConfigList(dataparams);
        }

        public IList<ETLDbConfig> GetETLDbConfigList(SqlParameter[] dataparams)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetETLDbConfigList(dataparams);
        }
        public IList<ETLCallBackConfig> GetCallBackConfigList(IDataParameter[] dataparams)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetCallBackConfigList(dataparams);
        }

        public IList<ETLCallBackPara> GetCallBackParasList(IDataParameter[] dataparams)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetCallBackParasList(dataparams);
        }
        public IList<ETLWDCConfig> GetWDCConfigList(IDataParameter[] dataparams)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetWDCConfigList(dataparams);
        }
        public IList<SysUserInfo> GetEtlSourceUserList(IDataParameter[] dataparams)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetContactById(dataparams);
        }
        public DataTable GetTableList(IDataParameter[] dataparams)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetTableList(dataparams);
        }

        public int InsertJobConfigStep(IDataParameter[] parasJobConfig)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.InsertJobConfigStep(parasJobConfig);
        }

        public int InsertCallBack(IDataParameter[] callBackParas)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.InsertCallBack(callBackParas);
        }

        public int delCBParas(SqlParameter[] delCbParas)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.delCBParas(delCbParas);
        }

        public List<ETL_Source_View_ColumnConfigInfo> GetTableInfoList(string targetID, string connstr, string connType, string tbOwer)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetTableInfoList(targetID, connstr, connType, tbOwer);
        }

        public DataTable GetSourceViewTableBySql(string connstr, string connType)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetSourceViewTableBySql(connstr, connType);
        }

        public DataTable GetALLColumnType()
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetALLColumnType();
        }
         
        public int UpDBStatus(string id,int status)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.UpDBStatus(id, status);
        }
        public int SourceDelete(SqlParameter[] par)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.SourceDelete(par);
        }
        public bool SourceDeleteCheck(string sourID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.SourceDeleteCheck(sourID);
        }

        public DataTable UpateTask(SqlParameter[] par)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.UpateTask(par);
        }

        public DataTable GetSourceViewBySystemID(SqlParameter[] paras1)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetSourceViewBySystemID(paras1);
        }

        public int SourceUpdateStatus(SqlParameter[] par)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.SourceUpdateStatus(par);
        }

        public bool GetSourceSystemByName(SqlParameter[] par)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetSourceSystemByName(par);
        }

        public int InsertDbConfig(IDataParameter[] dictionaryInfo)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.InsertDbConfig(dictionaryInfo);
        }

        public IList<ETLDbConfig> LoadListBySysID(string sysID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.LoadListBySysID(sysID);
        }

        #region 新的函数

        #region 源系统管理 EtlSourceSystemInfo

        public EtlSourceSystemInfo GetEtlSourceSystemInfoById(string guid)
        {
            try
            {
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                return dal.GetEtlSourceSystemInfoById(guid);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "GetEtlSourceSystemInfoById", AppError.EROR, 0, ex, "获取ETLSourceBll信息出错。",
                                String.Format("guid = {0}", guid));
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }


        /// <summary>
        /// 往ETL_SourceSystem表内添加新记录
        /// 插入成功：1
        /// SourceSysName相同：2
        /// SourceSysCode相同：3
        /// </summary>
        /// <param name="sourceInfo"></param>
        /// <returns></returns>
        public int InsertWithExist(EtlSourceSystemInfo sourceInfo)
        {
            try
            {
                int result = 0;
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                var list = dal.GetByNameAndCode(sourceInfo.SourceSysName, sourceInfo.SourceSysCode);
                if (list.Count == 0)
                {
                    result = dal.Insert(sourceInfo);
                }
                else
                {
                    if (list[0].SourceSysName.Equals(sourceInfo.SourceSysName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        result = 2;
                    }
                    else
                    {
                        result = 3;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "InsertWithExist", AppError.EROR, 0, ex, "添加ETLSourceBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        /// <summary>
        /// 更新ETL_SourceSystem表记录
        /// 插入成功：1
        /// SourceSysName相同：2
        /// SourceSysCode相同：3
        /// </summary>
        /// <param name="sourceInfo"></param>
        /// <returns></returns>
        public int Update2(EtlSourceSystemInfo sourceInfo)
        {
            try
            {
                int result = 0;
                ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
                var list = dal.GetByNameWithOutGUID(sourceInfo.GUID, sourceInfo.SourceSysName);
                if (list.Count == 0)
                {
                    result = dal.Update2(sourceInfo);
                }
                else
                {
                    if (list[0].SourceSysName.Equals(sourceInfo.SourceSysName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        result = 2;
                    }
                    else
                    {
                        result = 3;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_SourceSystemBLL", "Update", AppError.EROR, 0, ex, "更新ETLSourceBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeUpdate, ex);
            }
        }
        #endregion

        #region ETLDbConfig

        public IList<ETLDbConfig> GetDbConfigBySysID(string sysID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetDbConfigBySysID(sysID);
        }

        public ETLDbConfig GetDbConfigByID(string ID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetDbConfigByID(ID);
        }
        public int AddDbConfig(ETLDbConfig dbConfigInfo)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.AddDbConfig(dbConfigInfo);
        }
        public int UpdateBigDateTagConfig(string sysID,string DBID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.UpdateBigDateTagConfig(sysID,DBID);
        }
        public int UpdateDbConfig(ETLDbConfig dbConfigInfo)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.UpdateDbConfig(dbConfigInfo);
        }
        public int AddWDCConfig(ETLWDCConfig model)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.AddWDCConfig(model);
        }

        public int DeleteWDCConfig(string guid)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.DeleteWDCConfig(guid);
        }
        public int UpdateWDCConfig(ETLWDCConfig model)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.UpdateWDCConfig(model);
        }
        public int UpDateDbConfig(ETLDbConfig dbConfigInfo)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.UpDateDbConfig(dbConfigInfo);
        }

        public int DeleteDbConfig(ETLDbConfig dbConfigInfo)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.DeleteDbConfig(dbConfigInfo);
        }

        public int DeleteDbConfigBySysID(string sysID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.DeleteDbConfigBySysID(sysID);
        }


        #endregion

        #region 源系统联系人信息

        public int DeleteContact(string guid, string sysID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.DeleteContact(guid, sysID);
        }

        public int DeleteContactBySysID(string sysID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.DeleteContactBySysID(sysID);
        }

        public int DeleteContactBySysID(string sysID, int sysType)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.DeleteContactBySysID(sysID, sysType);
        }

        public int AddContact(EtlContactInfo contactInfo)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.AddContact(contactInfo);
        }

        #endregion

        #region ETL_Source_ViewConfig

        public List<ETL_Source_ViewConfigInfo> GetSourceViewConfigBySystemID(string sysID)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetSourceViewConfigBySystemID(sysID);
        }
        #endregion

        #region VW_ColumnTypeList
        public List<VW_ColumnTypeInfo> GetALLColumnTypeList()
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetALLColumnTypeList();
        }
        #endregion

        #region 公共存储过程单元

        public int InsertJobConfigStep(string viewID, string createUser)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.InsertJobConfigStep(viewID, createUser);
        }
        #endregion

        #region 对源系统的表操作

        public DataTable GetSourceTableData(string viewName, string connstr, string connType, string orderBy, string asc, string[] sql, IDataParameter[] para)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetSourceTableData(viewName, connstr, connType, orderBy, asc, sql, para);
        }
        #endregion

        #region 读取本地映射数据表数据

        public DataTable GetLocalTableData(string tableName, string columns, string orderBy, bool asc, int recordCount, string[] sql, List<SqlParameter> para)
        {
            ETL_SourceSystemDAL dal = new ETL_SourceSystemDAL(loginInfo);
            return dal.GetLocalTableData(tableName, columns, orderBy, asc, recordCount, sql, para);
        }
        #endregion

        #region 读取目录中的文件

        #endregion

        #endregion
    }
}